package com.lyshop.jinding.utils;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;

public class GlideUtils {
    /**
     * 圆角配置
     * @param roundCorners
     * @return
     */
    public static RequestOptions getImageRoundOptions(int roundCorners){
        RequestOptions mRoundOptions = new RequestOptions()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .centerCrop()
                .transform(new RoundedCorners(roundCorners));
        return mRoundOptions;
    }

    public static RequestOptions getImageDefaultOptions(){
        RequestOptions mImageOptions = RequestOptions.centerCropTransform()
                .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
                .skipMemoryCache(false);
        return mImageOptions;
    }

    public static RequestOptions getFitxyImageDefaultOptions(){
        RequestOptions mImageOptions = new RequestOptions()
                .fitCenter()
                .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
                .skipMemoryCache(false);
        return mImageOptions;
    }

    /**
     * 展示圆角图片
     * @param context
     * @param url
     * @param view
     * @param roundCorners
     */
    public static void showImageRoundOptions(Context context, String url, ImageView view, int roundCorners){
        Glide.with(context).load(url).apply(getImageRoundOptions(roundCorners)).into(view);
    }

    /**
     * 展示正常图片
     * @param context
     * @param url
     * @param view
     */
    public static void showImageOptions(Context context, String url, ImageView view){
        Glide.with(context).load(url).apply(getImageDefaultOptions()).into(view);
    }

    /**
     * 展示正常图片 广告位
     * @param context
     * @param url
     * @param view
     */
    public static void showImageFitxyOptions(Context context, String url, ImageView view){
        Glide.with(context).load(url).apply(getFitxyImageDefaultOptions()).into(view);
    }
}
